<html class="no-js">
<head>
  <meta charset="utf-8"> 
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="assets/css/admin.css">
  <link rel="stylesheet" href="assets/css/common.css"> 
  <script src="assets/js/jquery.min.js"></script>
  <script src="assets/js/amazeui.min.js"></script>
  <script src="assets/js/app.js"></script>

  <link href="um/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
  <script type="text/javascript" charset="utf-8" src="um/umeditor.config.js"></script>
  <script type="text/javascript" charset="utf-8" src="um/umeditor.min.js"></script>
  <script type="text/javascript" src="um/lang/zh-cn/zh-cn.js"></script>

</head>
<body>

  <?php require_once("header.php");?>
  <?php require_once("slider.php");?>
  <!-- content start -->
  <div class="admin-content content">

    <div class="am-tabs am-margin" data-am-tabs>

      <div class="am-tabs-bd">
        <!-- 正文    -->
        <div class="am-tab-panel am-fade" id="tab2">
          <form class="am-form">
            <div class="am-g am-margin-top">
              <div class="am-u-sm-4 am-u-md-2 am-text-right">
                标题
              </div>
              <div class="am-u-sm-8 am-u-md-4">
                <input type="text" name="title" class="am-input-sm">
              </div>
              <div class="am-hide-sm-only am-u-md-6">*必填</div>
            </div>

           
            <div class="am-g am-margin-top-sm">
              <div class="am-u-sm-12 am-u-md-2 am-text-right admin-form-text">
                描述
              </div>
              <div class="am-u-sm-8 am-u-md-10" style="height:60%;">
                <textarea id="myEditor"  name="body" placeholder="请使用富文本编辑插件"></textarea>
              </div>
            </div>

          </form>
        </div>

      </div>
    </div>

    <div class="am-margin">
      <button type="button" onClick="app.add_art()" class="am-btn am-btn-primary am-btn-xs">提交保存</button>
      <button type="reset" class="am-btn am-btn-primary am-btn-xs">放弃保存</button>
    </div>
  </div>

</div>
<a class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>

<?php require_once("footer.php");?>

<script>
  var um = UM.getEditor('myEditor',{
    	imageUrlPrefix:"/",
  });

  app={
    url:"../core/src/article.php",
    key:0,
    GET:function(name){
      
      var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
      if(reg.test(location.href)){
        return unescape(RegExp.$2.replace(/\+/g, " "));
      }

      return "";

    },
    load:function(){ 
      var key=this.GET("key");

      if(key != undefined){
          var url=this.url;
          console.log("66666");
      console.log(key);
      console.log("66666");
          $.post(url,{"func":"load","key":key},function(d,e){
            var content=d.content;
            $("input[name='title']").val(content.title);
            $("input[name='from']").val(content.from);
            setTimeout(function(){
              um.setContent(content.body);
            },1000);
          });
        } 
      },
      add_art:function(){
          var from={
            "title":$("input[name='title']").val(),
            "body":um.getContent(),
          };
          if(!from.title || !from.body){
            alert("补全内容");
            return false;
          }
          var key=(this.GET("key")==undefined)?0:this.GET("key");  
           $.post(this.url,{"func":"add_art","key":key,"edit":from},function(d,e){
                if(d.status){
                    alert("添加成功！");
                    location.href="list.php";
                }
            });
      },


    }; 
    $(function(){
        app.load();
    });
    </script>
  </body>
  </html>
